ordersController = BaseController.extend({
	template:'orders',
	center:'订单列表',
	mainView: 'orders',
	goodsListData:new ReactiveVar([]),
	waitOn:function(){
		let self = this;
		var partnerInfo = this.currentUser();
		switch (partnerInfo.level_name){
			case "company":
			Meteor.subscribe('orderGoods',{company_partner_id:parseInt(partnerInfo.id), state:{"$in": ['pay','refunding','refunded','over','apply']}}, {sort:{id:-1}});
			break;
			case "platoon":
			Meteor.subscribe('orderGoods',{platoon_partner_id:parseInt(partnerInfo.id), state:{"$in": ['pay','refunding','refunded','over','apply']}}, {sort:{id:-1}});
			break;
			case "monitor":
			Meteor.subscribe('orderGoods',{monitor_partner_id:parseInt(partnerInfo.id), state:{"$in": ['pay','refunding','refunded','over','apply']}}, {sort:{id:-1}});
			break;
			default:
			break;
		}
		console.log('dddf'+partnerInfo.id)
		if(typeof(partnerInfo.id) != 'undefined'){
			console.log('test')
			this.get('common/get-partner-goods',{partner_id:partnerInfo.id,level_name:partnerInfo.level_name,limit:100}).then(function(res){
				var arr = [];
				var data = res.data;
				for(var i in data){
					arr.push(data[i])
				}
				self.goodsListData.set(arr);
			},function(err){
				console.log(err)
			})
		}
		this.selector = new ReactiveVar();
		this.selector.set({});
	},
	onCreated:function(){

	},
	onRendered:function(self){
		var myApp = new Framework7({
			modalTitle: "提示",
			modalButtonOk: "确定",
			modalButtonCancel: "取消",
		});
		var $$ = Dom7;
		/*捕获商品名*/
		var selectors = {};
		$('#sid').change(function(){
			var selectValue = $('#sid').val();
			selectors.goods_id = parseInt(selectValue);
			self.selector.set(selectors);
		});

		var now = new Date();
		var today = self.getDateStr(now, 0);
		var startToday = self.getDateStart(now, 0);
		var startYesterDay = self.getDateStart(now, -1);
		var time = self.getRealTime(now, 0);
		var timet = self.dateToTime(time);

		$('#datePickerStart').val(today);
		$('#datePickerEnd').val(today);
		$('#datePickerEnd,#datePickerStart').on('change',function(){
			if ($('#datePickerEnd').val() < $('#datePickerStart').val()){
				myApp.alert('日期选择有误，请重新选择', function(){
					$('#datePickerStart').val(today);
					$('#datePickerEnd').val(today);
				});
			}else {
				var startt = self.dateToTime($('#datePickerStart').val()+" 00:00:00");
				var endt = self.dateToTime($('#datePickerEnd').val()+" 23:59:59")
				console.log(startt)
				if ($('#datePickerEnd').val() == today){
					selectors.pay_time = {"$lte": timet, "$gte":startt};
				}else {
					selectors.pay_time = {"$lte": endt, "$gte": startt};
				}
				self.selector.set(selectors);
			}
		});
	},
	data: function() {
		let self = this;
		return {
			getGoods: function(){
				return self.goodsListData.get();
			},
			ordersList: function(){
				return OrderGoods.find(self.selector.get()).fetch();
			}
		};
	}
})
